        <!DOCTYPE html>
        <html>
        <head>
                <meta charset="utf-8">
        <title>DistanceProxy class / box2d Library / Dart Documentation</title>
        <link rel="stylesheet" type="text/css"
            href="../styles.css">
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800" rel="stylesheet" type="text/css">
        <link rel="shortcut icon" href="../favicon.ico">
        
        </head>
        <body data-library="box2d" data-type="DistanceProxy">
        <div class="page">
        <div class="header">
          <a href="../index.html"><div class="logo"></div></a>
          <a href="../index.html">Dart Documentation</a>
         &rsaquo; <a href="../box2d.html">box2d</a> &rsaquo; <a href="../box2d/DistanceProxy.html">DistanceProxy</a>        <div id="search-box">
          <input type="search" name="q" id="q" autocomplete="off"
              class="search-input" placeholder="Search API">
        </div>
        
      </div>
      <div class="drop-down" id="drop-down"></div>
      
        <div class="nav">
        
</div>
<div class="content">
        <h2><strong>DistanceProxy</strong>
          class
        </h2>
        
<button id="show-inherited" class="show-inherited">Hide inherited</button>
<div class="doc">
<pre class="source">
class DistanceProxy {
 final List&lt;vec2&gt; vertices;
 int count;
 num radius;

 /**
  * Constructs a new DistanceProxy.
  */
 DistanceProxy() :
   vertices = new List&lt;vec2&gt;(Settings.MAX_POLYGON_VERTICES),
   count = 0,
   radius = 0 {

     for(int i = 0; i &lt; vertices.length; ++i)
       vertices[i] = new vec2.zero();
   }

 /**
  * Initialize the proxy using the given shape. The shape
  * must remain in scope while the proxy is in use.
  */
 void setFromShape(shape) {
   // If the shape is a circle...
   if (shape.type == ShapeType.CIRCLE) {
     vertices[0].copyFrom(shape.position);
     count = 1;
     radius = shape.radius;

     // If the shape is a polygon...
   } else if (shape.type == ShapeType.POLYGON) {
     count = shape.vertexCount;
     radius = shape.radius;
     for(int i = 0; i &lt; count; i++) {
       vertices[i].copyFrom(shape.vertices[i]);
     }
   } else {
     // Should always be a circle or a polygon.
     assert(false);
   }
 }

 /**
  * Get the supporting vertex index in the given direction.
  */
 int getSupport(vec2 direction) {
   int bestIndex = 0;
   num bestValue = dot(vertices[0], direction);
   for (int i = 1; i &lt; count; ++i) {
     num value = dot(vertices[i], direction);
     if(value &gt; bestValue) {
       bestIndex = i;
       bestValue = value;
     }
   }

   return bestIndex;
 }

 /**
  * Get the supporting vertex in the given direction.
  */
 vec2 getSupportVertex(vec2 direction) =&gt; vertices[getSupport(direction)];
}
</pre>
</div>
<div>
<h3>Constructors</h3>
<div class="method"><h4 id="DistanceProxy">
<button class="show-code">Code</button>
new <strong>DistanceProxy</strong>() <a class="anchor-link" href="#DistanceProxy"
              title="Permalink to DistanceProxy.DistanceProxy">#</a></h4>
<div class="doc">
<p>Constructs a new DistanceProxy.</p>
<pre class="source">
DistanceProxy() :
 vertices = new List&lt;vec2&gt;(Settings.MAX_POLYGON_VERTICES),
 count = 0,
 radius = 0 {

   for(int i = 0; i &lt; vertices.length; ++i)
     vertices[i] = new vec2.zero();
 }
</pre>
</div>
</div>
</div>
<div>
<h3>Properties</h3>
<div class="field"><h4 id="count">
<button class="show-code">Code</button>
int         <strong>count</strong> <a class="anchor-link"
            href="#count"
            title="Permalink to DistanceProxy.count">#</a>
        </h4>
        <div class="doc">
<pre class="source">
count
</pre>
</div>
</div>
<div class="field"><h4 id="radius">
<button class="show-code">Code</button>
num         <strong>radius</strong> <a class="anchor-link"
            href="#radius"
            title="Permalink to DistanceProxy.radius">#</a>
        </h4>
        <div class="doc">
<pre class="source">
radius
</pre>
</div>
</div>
<div class="field"><h4 id="vertices">
<button class="show-code">Code</button>
final List&lt;<a href="../vector_math/vec2.html">vec2</a>&gt;         <strong>vertices</strong> <a class="anchor-link"
            href="#vertices"
            title="Permalink to DistanceProxy.vertices">#</a>
        </h4>
        <div class="doc">
<pre class="source">
vertices
</pre>
</div>
</div>
</div>
<div>
<h3>Methods</h3>
<div class="method"><h4 id="getSupport">
<button class="show-code">Code</button>
int <strong>getSupport</strong>(<a href="../vector_math/vec2.html">vec2</a> direction) <a class="anchor-link" href="#getSupport"
              title="Permalink to DistanceProxy.getSupport">#</a></h4>
<div class="doc">
<p>Get the supporting vertex index in the given direction.</p>
<pre class="source">
int getSupport(vec2 direction) {
 int bestIndex = 0;
 num bestValue = dot(vertices[0], direction);
 for (int i = 1; i &lt; count; ++i) {
   num value = dot(vertices[i], direction);
   if(value &gt; bestValue) {
     bestIndex = i;
     bestValue = value;
   }
 }

 return bestIndex;
}
</pre>
</div>
</div>
<div class="method"><h4 id="getSupportVertex">
<button class="show-code">Code</button>
<a href="../vector_math/vec2.html">vec2</a> <strong>getSupportVertex</strong>(<a href="../vector_math/vec2.html">vec2</a> direction) <a class="anchor-link" href="#getSupportVertex"
              title="Permalink to DistanceProxy.getSupportVertex">#</a></h4>
<div class="doc">
<p>Get the supporting vertex in the given direction.</p>
<pre class="source">
vec2 getSupportVertex(vec2 direction) =&gt; vertices[getSupport(direction)];
</pre>
</div>
</div>
<div class="method"><h4 id="setFromShape">
<button class="show-code">Code</button>
void <strong>setFromShape</strong>(shape) <a class="anchor-link" href="#setFromShape"
              title="Permalink to DistanceProxy.setFromShape">#</a></h4>
<div class="doc">
<p>Initialize the proxy using the given shape. The shape
must remain in scope while the proxy is in use.</p>
<pre class="source">
void setFromShape(shape) {
 // If the shape is a circle...
 if (shape.type == ShapeType.CIRCLE) {
   vertices[0].copyFrom(shape.position);
   count = 1;
   radius = shape.radius;

   // If the shape is a polygon...
 } else if (shape.type == ShapeType.POLYGON) {
   count = shape.vertexCount;
   radius = shape.radius;
   for(int i = 0; i &lt; count; i++) {
     vertices[i].copyFrom(shape.vertices[i]);
   }
 } else {
   // Should always be a circle or a polygon.
   assert(false);
 }
}
</pre>
</div>
</div>
</div>
        </div>
        <div class="clear"></div>
        </div>
        <div class="footer">
          
        </div>
        <script async src="../client-live-nav.js"></script>
        </body></html>
        
